﻿using System;
using System.Collections.Generic;
using DC2010.Objects.Base;
using System.Xml.Serialization;
using DC2010.Objects.Common;

namespace DC2010.Objects.Data
{
    [Serializable]
    public class PartyData : BaseData
    {
        public PartyData()
        {
            MembersData = new List<CreatureData>();
            Members = new List<string>();
            Location = new DungeonLoc();
            IndexedCreatures = new List<KeyValue>();
        }

        /// <summary>
        /// Id of this party leader
        /// </summary>
        public string PartyLeaderId { get; set; }

        /// <summary>
        /// Some more damage applied.
        /// </summary>
        public bool IsPartySleeping { get; set; }

        /// <summary>
        /// When looking north..Up
		/// 0, 1
		/// 2, 3
		///
		/// 5 is center! for one is one full tile monsters
        /// </summary>
        public List<KeyValue> IndexedCreatures { get; set; }


        /// <summary>
        /// Members
        /// </summary>
        [XmlIgnore]
        public List<CreatureData> MembersData { get; set; }

        public List<string> Members { get; set; }

        /// <summary>
        /// 60; // About 10 seconds
        /// </summary>
        public int LastMonsterAttackTime { get; set; }

        public string LayerId { get; set; }

        public DungeonLoc Location { get; set; }

        public int LastPartyMoveTime { get; set; }

        public int Time { get; set; }
		
		public int PartyMoveDisableTimer { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public Directions Facing { get; set; }

        public bool IsMonsterParty
        {
            get
            {
                foreach (var creatureData in MembersData)
                {
                    if (creatureData.CreatureType == CreatureType.Monster)
                        return true;
                }

                return false;
            }
        }
		
	    public PartyGfx Gfx
        {
            get
            {
                if (!string.IsNullOrEmpty(GfxId))
                {
                    return Root.I.PartySystem.GetGfx(GfxId);
                }

                return null;
            }
        }		

        private PartyLogic _l;
        public PartyLogic L
        {
            get
            {
                if (_l == null)
                    _l = new PartyLogic(this);

                return _l;
            }
        }

        public CreatureData GetCreatureByIndex(int index)
        {
            if ((MembersData != null) &&
            (MembersData.Count >= index))
            {
                return MembersData[index-1];
            }

            return null;
        }


        public void MoveParty(DungeonLoc loc)
        {
            //check
            
            //move
            Location = loc;
        }
    }
}
